
use "master sept032018.dta", clear

ssc install coefplot
ssc install estout
set scheme s1mono
net install grc1leg, from("http://www.stata.com/users/vwiggins/")

*Generate compliance measure
gen declare=declared/profitret

*Generate fiscal variables
gen benefits = 0
replace benefits=1 if session == 13 | session==14 | session==15 | session==16 | session==17 | session==18 |session==22 | session==23 | session==24 | session==19 | session==20 | session==21
gen taxregime=0
replace taxregime=1 if session == 13 | session==14 | session==15 | session==1 | session==2 | session==3 | session==16 |session==17 | session==18 | session==4| session==5 | session==6 

*Generate treatment variables

encode treatment, generate(treatment2)
describe
label define treatmentl 1 "Progressive benefits,proportional taxation" 2 "Progressive benefits,progressive taxation" 3 "Proportional benefits,proportional taxation" 4 "Proportional benefits,progressive taxation"
label values treatment2 treatmentl

*Generate groups
egen s1 = concat(auditrate session period group), punct(-)
by s1, sort: egen rank=rank(profitret), unique 
by s1, sort: gen size = _N
drop if size>4

*Generate real income rank
label variable rank "Income rank of the subject"
label define rankl 1 "1" 2 "2" 3 "3" 4 "4"
label values rank rankl

*Generate declared income rank

egen d1 = concat(auditrate session period group), punct(-)
by d1, sort: egen drank=rank(declared), unique 
by d1, sort: gen dsize = _N
drop if dsize!=4
label variable drank "Declared income rank of the subject"
label define drankl 1 "1" 2 "2" 3 "3" 4 "4"
label values drank drankl

egen subject_unique_no = concat(session subject), punct(-)
gen income_level=0
replace income_level=1 if rank==3 | rank==4
label define incomel 0 "Poor" 1 "Rich"
label values income_level incomel

*Generate tax treatment variables

gen tax=0
replace tax=1 if taxratetoshow==50
label define taxl 0 "Low tax" 1 "High tax"
label values tax taxl

*Generate audit treatment variables

gen audit=0
replace audit=1 if auditrate==10
label define auditl 0 "No audits" 1 "0.1 probability of being audited"
label values audit auditl

*Generate altruism variables

gen altruism=offerdg/1000
gen alt=0
replace alt=1 if altruism>0.49

*Generate session-group variables

egen session_group_id = concat(session period group), punct(-)
egen session_group_id2 = concat(session group period audit), punct(-)

egen period2 = concat(period audit), punct(-)

*Generate additional income variables

gen log_profitret=log(profitret)
gen demeaned_rank = rank- 1


*Generate additional fiscal treatment variables

gen progressive_tax=0
replace progressive_tax=1 if treatment2==2 | treatment2==4

gen progressive_benefit=0
replace progressive_benefit=1 if treatment2==1 | treatment2==2

*Generate unique subject variables

encode subject_unique_no, generate(unique)

*Generate period variables

encode period2, generate(p2)


****TABLE 1

reg declare ib(3).treatment2 i.tax i.audit i.period, robust cluster(session_group_id2)
estimates store t1_1, title(Model 1)

reg declare ib(3).treatment2 c.demeaned_rank i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store t1_2, title(Model 2)

reg declare ib(3).treatment2 c.log_profitret i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store t1_3, title(Model 2)

reg declare ib(3).treatment2 c.demeaned_rank i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store t1_4, title(Model 2)

reg declare ib(3).treatment2 c.log_profitret i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store t1_5, title(Model 2)


label variable log_profitret "log(Earnings)"

esttab t1_1 t1_2 t1_3 t1_4 t1_5 using table1.tex, indicate("Period FE = *.period" "Individual controls = *.ideology") replace varwidth(25) label nobaselevels  interaction(" $\times$ ") style(tex) star(* 0.1 ** .05 *** .01)  drop(jgender age_subject safechoices) cells(b(star fmt(2)) se(par fmt(2))) stats(N r2_a vce, labels("Observations" "Adjusted \(R^{2}\)" "Cluster")) substitute (cluster "Group" "Group" "Group")

****FIGURE 1

reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit  i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(treatment2=(1 2 3 4) rank=(1) alt=(0) tax=1 audit=1) post
estimate store rank1_a0



reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit  i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(treatment2=(1 2 3 4) rank=(1) alt=(1) tax=1 audit=1) post
estimate store rank1_a1


coefplot(rank1_a0,label(Non-altruistic) mcolor(pink) msize(medsmall) mlabcolor(pink) lcolor(pink) msymbol(O)) //////
(rank1_a1,label(Altruistic) mcolor(navy) msize(medsmall) mlabcolor(navy) lcolor(pink) msymbol(S)), ///
grid(between(*1.5) glpattern(dash) glwidth(*0.5) glcolor(gray)) vertical  ///
nooffsets ciopts(lcolor(black) recast(rcap)) graphregion(fcolor(white))legend(position(6) rows(1) size(*0.8)) ytitle("") ///
xlabel(0.75 " " 1 `" "(+) benefits,"   "(-) taxes" "' 2 `" "(+) benefits,"   "(+) taxes" "' 3 `" "(-) benefits,"   "(-) taxes" "' 4 `" "(-) benefits,"   "(+) taxes" "' 4.245" ",notick labsize(*0.7))  ///
ylabel(0.3(0.1)1, grid) yscale(range(0.4(0.1)1)) ///
 title("Poorest, Tax = 50%", size(*0.8)) name(rank1, replace) 


reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit  i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(treatment2=(1 2 3 4) rank=(4) alt=(0) tax=1 audit=1) post
estimate store rank4_a0


reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit  i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(treatment2=(1 2 3 4) rank=(4) alt=(1) tax=1 audit=1) post
estimate store rank4_a1


coefplot(rank4_a0,label(Non-altruistic) mcolor(pink) msize(medsmall) mlabcolor(pink) lcolor(pink) msymbol(O)) //////
(rank4_a1,label(Altruistic) mcolor(navy) msize(medsmall) mlabcolor(navy) lcolor(pink) msymbol(S)), ///
grid(between(*1.5) glpattern(dash) glwidth(*0.5) glcolor(gray)) vertical  ///
nooffsets ciopts(lcolor(black) recast(rcap)) graphregion(fcolor(white))legend(position(6) rows(1) size(*0.8)) ytitle("") ///
xlabel(0.75 " " 1 `" "(+) benefits,"   "(-) taxes" "' 2 `" "(+) benefits,"   "(+) taxes" "' 3 `" "(-) benefits,"   "(-) taxes" "' 4 `" "(-) benefits,"   "(+) taxes" "' 4.245" ",notick labsize(*0.7))  ///
ylabel(0.3(0.1)1, grid) yscale(alt) title("Richest, Tax = 50%", size(*0.8)) name(rank4, replace) 


grc1leg rank1 rank4, rows(1) ycommon xcommon name(combgraph, replace)
graph display combgraph, xsize(10) ysize(6) 
graph export 3way.png, replace


reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit  i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(treatment2=(1 2 3 4) rank=(1) alt=(0) tax=0 audit=1) post
estimate store rank1_a0


reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit  i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(treatment2=(1 2 3 4) rank=(1) alt=(1) tax=0 audit=1) post
estimate store rank1_a1


coefplot(rank1_a0,label(Non-altruistic) mcolor(pink) msize(medsmall) mlabcolor(pink) lcolor(pink) msymbol(O)) //////
(rank1_a1,label(Altruistic) mcolor(navy) msize(medsmall) mlabcolor(navy) lcolor(pink) msymbol(S)), ///
grid(between(*1.5) glpattern(dash) glwidth(*0.5) glcolor(gray)) vertical  ///
nooffsets ciopts(lcolor(black) recast(rcap)) graphregion(fcolor(white))legend(position(6) rows(1) size(*0.8)) ytitle("") ///
xlabel(0.75 " " 1 `" "(+) benefits,"   "(-) taxes" "' 2 `" "(+) benefits,"   "(+) taxes" "' 3 `" "(-) benefits,"   "(-) taxes" "' 4 `" "(-) benefits,"   "(+) taxes" "' 4.245" ",notick labsize(*0.7))  ///
ylabel(0.3(0.1)1, grid) yscale(range(0.4(0.1)1)) ///
 title("Poorest, Tax = 25%", size(*0.8)) name(rank1t0, replace) 


reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit  i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(treatment2=(1 2 3 4) rank=(4) alt=(0) tax=0 audit=1) post
estimate store rank4_a0


reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit  i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(treatment2=(1 2 3 4) rank=(4) alt=(1) tax=0 audit=0) post
estimate store rank4_a1


coefplot(rank4_a0,label(Non-altruistic) mcolor(pink) msize(medsmall) mlabcolor(pink) lcolor(pink) msymbol(O)) //////
(rank4_a1,label(Altruistic) mcolor(navy) msize(medsmall) mlabcolor(navy) lcolor(pink) msymbol(S)), ///
grid(between(*1.5) glpattern(dash) glwidth(*0.5) glcolor(gray)) vertical  ///
nooffsets ciopts(lcolor(black) recast(rcap)) graphregion(fcolor(white))legend(position(6) rows(1) size(*0.8)) ytitle("") ///
xlabel(0.75 " " 1 `" "(+) benefits,"   "(-) taxes" "' 2 `" "(+) benefits,"   "(+) taxes" "' 3 `" "(-) benefits,"   "(-) taxes" "' 4 `" "(-) benefits,"   "(+) taxes" "' 4.245" ",notick labsize(*0.7))  ///
ylabel(0.3(0.1)1, grid) yscale(alt) title("Richest, Tax = 25%", size(*0.8)) name(rank4t0, replace) 


grc1leg rank1t0 rank4t0 rank1 rank4, rows(2) xcommon ycommon name(combgraph, replace) l1(Predicted Ratio of Declared Earnings)

graph export 3wayt0.png, width(800) height(600) replace


graph display combgraph, xsize(16) ysize(8) 

****APPENDIX TABLE 2
egen num_max = max(rank), by(unique)
egen num_min = min(rank), by(unique)

preserve
duplicates drop unique, force
eststo clear
estpost tab num_min num_max          // posts counts
esttab using table_varrank.tex, cells("pct(fmt(2))") unstack noobs replace
restore

****APPENDIX FIGURE 2

graph bar (count) if session==2,over(rank) over(unique, lab(nolab)) asyvars stack percentage b1title(Subjects) ytitle(Percentage of Rank Frequency) 
graph export session2rank.png, replace

****APPENDIX FIGURE 3

reg declare ib(3).treatment2 c.demeaned_rank i.tax i.audit##c.safechoices##i.alt  i.ideology jgender age_subject  i.period, robust cluster(session_group_id)
margins, at(safechoices=(0 5 10)  alt=(0 1) tax=1 audit=(0 1)) post
marginsplot, xtitle("Risk averseness") ytitle("Ratio of declared earnings") title("")
graph export risk.png, replace

****APPENDIX TABLE 3
reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit i.period, robust cluster(session_group_id)
estimates store a3_1, title(Model 1)

reg declare i.alt##c.rank##ib(3).treatment2 i.tax i.audit  i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id)
estimates store a3_2, title(Model 2)

esttab a3_1 a3_2 using tablea3.tex, indicate("Period FE = *.period" "Individual controls = *.ideology") replace varwidth(25) label nobaselevels  interaction(" $\times$ ") style(tex) star(* 0.1 ** .05 *** .01)  drop(jgender age_subject safechoices) cells(b(star fmt(2)) se(par fmt(2))) stats(N r2_a vce, labels("Observations" "Adjusted \(R^{2}\)" "Cluster")) substitute (cluster "Group" "Group" "Group")


****APPENDIX TABLE 4

reg declare i.progressive_tax i.progressive_benefit i.tax i.audit i.period, robust cluster(session_group_id2)
estimates store a4_1, title(Model 1)

reg declare i.progressive_tax i.progressive_benefit c.demeaned_rank i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store a4_2, title(Model 2)

reg declare i.progressive_tax i.progressive_benefit c.log_profitret i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store a4_3, title(Model 2)

reg declare i.progressive_tax i.progressive_benefit c.demeaned_rank i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store a4_4, title(Model 2)

reg declare i.progressive_tax i.progressive_benefit c.log_profitret i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store a4_5, title(Model 2)


esttab a4_1 a4_2 a4_3 a4_4 a4_5 using tableAppendixSeperate.tex, indicate("Period FE = *.period" "Individual controls = *.ideology") replace varwidth(25) label nobaselevels  style(tex) star(* 0.1 ** .05 *** .01)  drop(jgender age_subject safechoices) cells(b(star fmt(2)) se(par fmt(2))) stats(N r2_a vce, labels("Observations" "Adjusted \(R^{2}\)" "Cluster")) substitute (cluster "Group" "Group" "Group")


****APPENDIX TABLE 5
reg declare ib(3).treatment2 c.demeaned_rank##i.audit i.tax i.period, robust cluster(session_group_id2)
estimates store a5_1, title(Model 1)

reg declare ib(3).treatment2 c.log_profitret##i.audit i.tax i.period, robust cluster(session_group_id2)
estimates store a5_2, title(Model 2)

reg declare ib(3).treatment2 c.demeaned_rank##i.audit i.tax i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store a5_3, title(Model 3)

reg declare ib(3).treatment2 c.log_profitret##i.audit i.tax i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store a5_4, title(Model 4)

esttab a5_1 a5_2 a5_3 a5_4 using tableAppAuditInc.tex, indicate("Period FE = *.period" "Individual controls = *.ideology") replace varwidth(25) label nobaselevels  interaction(" $\times$ ") style(tex) star(* 0.1 ** .05 *** .01)  drop(jgender age_subject safechoices) cells(b(star fmt(2)) se(par fmt(2))) stats(N r2_a vce, labels("Observations" "Adjusted \(R^{2}\)" "Cluster")) substitute (cluster "Group" "Group" "Group")

****APPENDIX TABLE 6

reg declare ib(3).treatment2##c.demeaned_rank i.audit i.tax i.period, robust cluster(session_group_id2)
estimates store a6_1, title(Model 1)

reg declare ib(3).treatment2##c.log_profitret i.audit i.tax i.period, robust cluster(session_group_id2)
estimates store a6_2, title(Model 2)

reg declare ib(3).treatment2##c.demeaned_rank i.audit i.tax i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store a6_3, title(Model 3)

reg declare ib(3).treatment2##c.log_profitret i.audit i.tax i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
estimates store a6_4, title(Model 4)


esttab a6_1 a6_2 a6_3 a6_4 using tableFiscalIncomeInt.tex, indicate("Period FE = *.period" "Individual controls = *.ideology") replace varwidth(25) label nobaselevels  interaction(" $\times$ ") style(tex) star(* 0.1 ** .05 *** .01)  drop(jgender age_subject safechoices) cells(b(star fmt(2)) se(par fmt(2))) stats(N r2_a vce, labels("Observations" "Adjusted \(R^{2}\)" "Cluster")) substitute (cluster "Group" "Group" "Group")



****APPENDIX FIGURE 5


reg declare i.progressive_tax##c.demeaned_rank##i.alt i.progressive_benefit##c.demeaned_rank##i.alt i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(progressive_tax=(0 1) demeaned_rank=(0) alt=(0) tax=1 audit=0) post
estimates store atriple_0, title(Model 1)

reg declare i.progressive_tax##c.demeaned_rank##i.alt i.progressive_benefit##c.demeaned_rank##i.alt i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(progressive_tax=(0 1) demeaned_rank=(0) alt=(1) tax=1 audit=0) post
estimates store atriple_1, title(Model 1)

coefplot(atriple_0,label(Non-altruistic) mcolor(pink) msize(medsmall) mlabcolor(pink) lcolor(pink) msymbol(O)) //////
(atriple_1,label(Altruistic) mcolor(navy) msize(medsmall) mlabcolor(navy) lcolor(pink) msymbol(S)), ///
grid(between(*1.5) glpattern(dash) glwidth(*0.5) glcolor(gray)) vertical  ///
nooffsets ciopts(lcolor(black) recast(rcap)) graphregion(fcolor(white))legend(position(6) rows(1) size(*0.8)) ytitle("") ///
ylabel(0.3(0.1)1, grid) yscale(range(0.4(0.1)1)) ///
xlabel(1 "Proportional Tax" 2 "Progressive Tax"  ,notick labsize(*0.7))  ///
 title("Poorest, Tax = 50%", size(*0.8)) name(rank1, replace) 

reg declare i.progressive_tax##c.demeaned_rank##i.alt i.progressive_benefit##c.demeaned_rank##i.alt i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(progressive_tax=(0 1) demeaned_rank=(3) alt=(0) tax=1 audit=0 ) post
estimates store atriple_0, title(Model 1)

reg declare i.progressive_tax##c.demeaned_rank##i.alt i.progressive_benefit##c.demeaned_rank##i.alt i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(progressive_tax=(0 1) demeaned_rank=(3) alt=(1) tax=1 audit=0) post
estimates store atriple_1, title(Model 1)

coefplot(atriple_0,label(Non-altruistic) mcolor(pink) msize(medsmall) mlabcolor(pink) lcolor(pink) msymbol(O)) //////
(atriple_1,label(Altruistic) mcolor(navy) msize(medsmall) mlabcolor(navy) lcolor(pink) msymbol(S)), ///
grid(between(*1.5) glpattern(dash) glwidth(*0.5) glcolor(gray)) vertical  ///
nooffsets ciopts(lcolor(black) recast(rcap)) graphregion(fcolor(white))legend(position(6) rows(1) size(*0.8)) ytitle("") ///
ylabel(0.3(0.1)1, grid) yscale(range(0.4(0.1)1)) ///
xlabel(1 "Proportional Tax" 2 "Progressive Tax"  ,notick labsize(*0.7))  ///
 title("Richest, Tax = 50%", size(*0.8)) name(rank3, replace) 
 
 grc1leg rank1 rank3, rows(1) ycommon xcommon name(combgraph, replace)
graph display combgraph, xsize(10) ysize(6) 
graph export APPENDX3wayTax.png, replace


****APPENDIX FIGURE 6


reg declare i.progressive_tax##c.demeaned_rank##i.alt i.progressive_benefit##c.demeaned_rank##i.alt i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(progressive_benefit=(0 1) demeaned_rank=(0) alt=(0) tax=1 audit=0) post
estimates store atriple_0, title(Model 1)

reg declare i.progressive_tax##c.demeaned_rank##i.alt i.progressive_benefit##c.demeaned_rank##i.alt i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(progressive_benefit=(0 1) demeaned_rank=(0) alt=(1) tax=1 audit=0) post
estimates store atriple_1, title(Model 1)

coefplot(atriple_0,label(Non-altruistic) mcolor(pink) msize(medsmall) mlabcolor(pink) lcolor(pink) msymbol(O)) //////
(atriple_1,label(Altruistic) mcolor(navy) msize(medsmall) mlabcolor(navy) lcolor(pink) msymbol(S)), ///
grid(between(*1.5) glpattern(dash) glwidth(*0.5) glcolor(gray)) vertical  ///
nooffsets ciopts(lcolor(black) recast(rcap)) graphregion(fcolor(white))legend(position(6) rows(1) size(*0.8)) ytitle("") ///
ylabel(0.3(0.1)1, grid) yscale(range(0.4(0.1)1)) ///
xlabel(1 "Proportional Benefit" 2 "Progressive Benefit"  ,notick labsize(*0.7))  ///
 title("Poorest, Tax = 50%", size(*0.8)) name(rank1, replace) 

reg declare i.progressive_tax##c.demeaned_rank##i.alt i.progressive_benefit##c.demeaned_rank##i.alt i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(progressive_benefit=(0 1) demeaned_rank=(3) alt=(0) tax=1 audit=0 ) post
estimates store atriple_0, title(Model 1)

reg declare i.progressive_tax##c.demeaned_rank##i.alt i.progressive_benefit##c.demeaned_rank##i.alt i.tax i.audit i.alt i.ideology jgender age_subject safechoices i.period, robust cluster(session_group_id2)
margins, at(progressive_benefit=(0 1) demeaned_rank=(3) alt=(1) tax=1 audit=0) post
estimates store atriple_1, title(Model 1)

coefplot(atriple_0,label(Non-altruistic) mcolor(pink) msize(medsmall) mlabcolor(pink) lcolor(pink) msymbol(O)) //////
(atriple_1,label(Altruistic) mcolor(navy) msize(medsmall) mlabcolor(navy) lcolor(pink) msymbol(S)), ///
grid(between(*1.5) glpattern(dash) glwidth(*0.5) glcolor(gray)) vertical  ///
nooffsets ciopts(lcolor(black) recast(rcap)) graphregion(fcolor(white))legend(position(6) rows(1) size(*0.8)) ytitle("") ///
ylabel(0.3(0.1)1, grid) yscale(range(0.4(0.1)1)) ///
xlabel(1 "Proportional Benefit" 2 "Progressive Benefit"  ,notick labsize(*0.7))  ///
 title("Richest, Tax = 50%", size(*0.8)) name(rank3, replace) 
 
grc1leg rank1 rank3, rows(1) ycommon xcommon name(combgraph, replace)
graph display combgraph, xsize(10) ysize(6) 
graph export APPENDX3wayBenefit.png, replace
